package cn.zhouchao.basic.controller;

import cn.zhouchao.basic.dto.BinderDto;
import cn.zhouchao.basic.dto.LoginAccountDto;
import cn.zhouchao.basic.dto.WxCodeDto;
import cn.zhouchao.basic.service.LoginService;
import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.basic.vo.LogininfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;
    /**
     * 账号密码登陆
     */
    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid LoginAccountDto dto) {
        LogininfoVo result = loginService.account(dto);
        return AjaxResult.me().success(result);
    }
    /**
     * 微信扫码登陆
     */
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WxCodeDto dto) {

        return loginService.wechat(dto);
    }
    /**
     * 微信扫码登陆
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody @Valid BinderDto dto) {
        LogininfoVo result = loginService.wechatBinder(dto);
        return AjaxResult.me().success(result);
    }
}
